<?php

namespace models\DAO;

use models\Exception\DAO\ModelDriverException;
use models\Exception\DAO\ModelException;
use models\Exception\DAO\ModelReflectionException;
use models\Exception\DAO\ModelSqlException;


/**
 * @SWG\Swagger(
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkproductSingleData",
 *          required={"errno", "errmsg", "data"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", type="object", ref="#/definitions/tbkproductSingleObj")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkproductSingleObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/tbkproductSingle")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkproductListData",
 *          required={"errno", "errmsg", "result"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", ref="#/definitions/tbkproductListObj"),
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkproductListObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/tbkproductData"),
 *          @SWG\Property(property="meta", ref="#/definitions/meta")
 *     ),
 *     @SWG\Definition(
 *          type="array",
 *          definition="tbkproductData",
 *          @SWG\Items(
 *              title="data", ref="#/definitions/tbkproductSingle"
 *          )
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkproductSingle",
 *          @SWG\Property(property="product_id", type="string", format="string",  description="商品编号"),
 *          @SWG\Property(property="type", type="integer", format="int32",  description="数据源(0为好单库,默认0)"),
 *          @SWG\Property(property="title", type="string", format="string",  description="商品标题"),
 *          @SWG\Property(property="short_title", type="string", format="string",  description="商品段标题"),
 *          @SWG\Property(property="category_id", type="integer", format="int32",  description="商品分类"),
 *          @SWG\Property(property="desc", type="string", format="string",  description="宝贝推荐语"),
 *          @SWG\Property(property="article", type="string", format="string",  description="推广导购文案"),
 *          @SWG\Property(property="link", type="string", format="string",  description="优惠券链接"),
 *          @SWG\Property(property="pic", type="string", format="string",  description="宝贝主图原始图像(由于图片原图过大影响加载速度，建议加上后缀_310x310.jpg)"),
 *          @SWG\Property(property="image", type="string", format="string",  description="推广长图(前面拼上http://img.haodanku.com/0_553757100845_1509175123)"),
 *          @SWG\Property(property="video_id", type="string", format="string",  description="商品视频ID(好单库商品,前面拼上http://cloud.video.taobao.com/play/u/1/p/1/e/6/t/1/)"),
 *          @SWG\Property(property="stats", type="integer", format="int32",  description="是否上线(0为否,1为是,默认1)"),
 *          @SWG\Property(property="recommend", type="integer", format="int32",  description="是否推荐(0为否,1为是,默认0)"),
 *          @SWG\Property(property="price", type="string", format="string",  description="商品售价"),
 *          @SWG\Property(property="end_price", type="string", format="string",  description="券后价"),
 *          @SWG\Property(property="coupon_price", type="string", format="string",  description="优惠券金额"),
 *          @SWG\Property(property="rate", type="string", format="string",  description="佣金比例"),
 *          @SWG\Property(property="commission", type="string", format="string",  description="佣金"),
 *          @SWG\Property(property="today_sales", type="integer", format="int32",  description="今日销量"),
 *          @SWG\Property(property="sales", type="integer", format="int32",  description="月销量"),
 *          @SWG\Property(property="sales_in_2_hours", type="integer", format="int32",  description="两小时内销量"),
 *          @SWG\Property(property="coupon_receive", type="integer", format="int32",  description="当天优惠券领取量"),
 *          @SWG\Property(property="coupon_num", type="integer", format="int32",  description="优惠券总数量"),
 *          @SWG\Property(property="coupon_explain", type="string", format="string",  description="优惠券使用条件"),
 *          @SWG\Property(property="coupon_start_time", type="string", format="string",  description="优惠券开始时间"),
 *          @SWG\Property(property="coupon_end_time", type="string", format="string",  description="优惠券结束时间"),
 *          @SWG\Property(property="general_index", type="integer", format="int32",  description="好单指数"),
 *          @SWG\Property(property="activity_type", type="string", format="string",  description="活动类型"),
 *          @SWG\Property(property="activity_link", type="string", format="string",  description="营销计划链接"),
 *          @SWG\Property(property="rebate_integral", type="string", format="string",  description="晒单成功后所得金豆"),
 *          @SWG\Property(property="parent_rebate", type="string", format="string",  description="晒单成功后上级所得金豆"),
 *          @SWG\Property(property="grand_parent_rebate", type="string", format="string",  description="晒单成功后上上级所得金豆"),
 *          @SWG\Property(property="is_favour", type="integer", format="integer",  description="是否收藏 0为否1为是")
 *     )
 * )
 */
class TbkproductModel extends BaseModel{
    /**
     * 商品编号
     */
    public $product_id = null;

    /**
     * 数据源(0为好单库,默认0)
     */
    public $type = null;

    /**
     * 商品标题
     */
    public $title = null;

    /**
     * 商品段标题
     */
    public $short_title = null;

    /**
     * 商品分类
     */
    public $category_id = null;

    /**
     * 宝贝推荐语
     */
    public $desc = "";

    /**
     * 推广导购文案
     */
    public $article = "";

    /**
     * 优惠券链接
     */
    public $link = null;

    /**
     * 宝贝主图原始图像(由于图片原图过大影响加载速度，建议加上后缀_310x310.jpg)
     */
    public $pic = null;

    /**
     * 推广长图(前面拼上http://img.haodanku.com/0_553757100845_1509175123)
     */
    public $image = null;

    /**
     * 商品视频ID(好单库商品,前面拼上http://cloud.video.taobao.com/play/u/1/p/1/e/6/t/1/)
     */
    public $video_id = null;

    /**
     * 是否上线(0为否,1为是,默认1)
     */
    public $stats = null;

    /**
     * 是否推荐(0为否,1为是,默认0)
     */
    public $recommend = null;

    /**
     * 商品售价
     */
    public $price = null;

    /**
     * 券后价
     */
    public $end_price = null;

    /**
     * 优惠券金额
     */
    public $coupon_price = null;

    /**
     * 佣金比例
     */
    public $rate = null;

    /**
     * 佣金
     */
    public $commission = null;

    /**
     * 今日销量
     */
    public $today_sales = null;

    /**
     * 月销量
     */
    public $sales = null;

    /**
     * 两小时内销量
     */
    public $sales_in_2_hours = null;

    /**
     * 当天优惠券领取量
     */
    public $coupon_receive = null;

    /**
     * 优惠券总数量
     */
    public $coupon_num = null;

    /**
     * 优惠券使用条件
     */
    public $coupon_explain = null;

    /**
     * 优惠券开始时间
     */
    public $coupon_start_time = null;

    /**
     * 优惠券结束时间
     */
    public $coupon_end_time = null;

    /**
     * 好单指数
     */
    public $general_index = null;

    /**
     * 活动类型
     */
    public $activity_type = null;

    /**
     * 营销计划链接
     */
    public $activity_link = null;
    /**
     * DAO对象
     */
    public $obj = '';

    /**
     * DAO对象数组
     */
    public $data = [];

    /**
     * 翻页对象
     */
    public $meta = null;

    /**
     * 当前页
     */
    public $page = 1;

    /**
     * 每页显示条数
     */
    public $page_size = 10;

    /**
     * 主键数组
     */
    public $primary_key_arr = ["product_id"];

    /**
     * 自增字段数组
     */
    public $auto_increment_key_arr = [];

    /**
     * 唯一字段
     */
    public $unique_key_arr = '';

    /**
     * 单例实例
     */
    static public $instance = null;

    /**
     * @return TbkproductModel|null
     * @throws ModelSqlException
     */
    static public function getInstance() {
        if(is_null(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * TbkproductModel constructor.
     * @throws ModelSqlException
     */
    public function __construct() {
        parent::__construct(str_replace("Model", "", substr(get_class($this), strrpos(get_class($this), "\\")+1)));
        $this->meta = new \stdClass();
    }

    /**
     * @throws ModelException
     */
    public function __clone() {
        throw new ModelException(
            str_replace('%s', get_class($this), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE_NO);
    }

    public function __destruct() {
        self::$instance = null;
    }

    /**
     * set属性
     *
     * __set.
     * @param string $name 参数名
     * @param string $value 参数值
     * @return $this
     */
    public function __set($name = "", $value = "") {
        $this->$name = $value;
        return $this;
    }

    /**
     * get属性
     *
     * __get.
     * @param string $name 参数名
     * @return mixed
     */
    public function __get($name = "") {
        return  $this->$name ;
    }

    /**
     * 创建tbkproductModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function insert() {
        return $this->insertRecord();
    }

    /**
     * 编辑tbkproductModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function update() {
        return $this->updateRecord();
    }

    /**
     * 删除tbkproductModel，需先指定主键
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function delete() {
        return $this->deleteRecord();
    }

    /**
     * 根据主键查询tbkproductModel，获取单条记录
     *
     * find.
     * @param int $primary_key 主键编号
     * @return $this
     * @throws ModelException
     * @throws ModelReflectionException
     */
    public function find($primary_key = 0) {
        $result = $this->findByPrimaryKey($primary_key);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询tbkproductModel，获取多条记录
     *
     * findOneBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findOneBy($condition = []) {
        $result = $this->findRecordBy($condition);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询tbkproductModel，获取多条记录
     *
     * findBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findBy($condition = []) {
        $count = $this->getCount($condition);
        $total = $count->fetchColumn();

        $this->data = [];
        $tbkp_obj = $this->findRecordBy($condition, $this->page, $this->page_size);

        $this->genMeta($total);
        $this->setModelProperty($tbkp_obj, true);

        return $this;
    }

    /**
     * 批量插入tbkproductModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchInsert() {
        return $this->batchInsertRecord();
    }

    /**
     * 批量删除tbkproductModel
     *
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchDelete() {
        $this->batchDeleteRecord();
    }

    /**
     * 生成批量生成update的sql
     *
     * @return bool|string
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function genBatchUpdateSql() {
        return $this->_genBatchUpdateSql();
    }

}
